package com.dayu.web.controller.recovery;

import java.util.List;

import com.dayu.recovery.domain.TransferGoods;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.enums.BusinessType;
import com.dayu.recovery.domain.WarehouseLogs;
import com.dayu.recovery.service.IWarehouseLogsService;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 出入库日志Controller
 * 
 * @author HK
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/recovery/warehouse")
public class WarehouseLogsController extends BaseController
{
    @Resource
    private IWarehouseLogsService warehouseLogsService;

    /**
     * 查询出入库日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WarehouseLogs warehouseLogs)
    {
        startPage();
        List<WarehouseLogs> list = warehouseLogsService.selectWarehouseLogsList(warehouseLogs);
        return getDataTable(list);
    }

    /**
     * 导出出入库日志列表
     */
    @PreAuthorize("@ss.hasPermi('recovery:warehouse:export')")
    @GetMapping("/export")
    public AjaxResult export(WarehouseLogs warehouseLogs)
    {
        List<WarehouseLogs> list = warehouseLogsService.selectWarehouseLogsList(warehouseLogs);
        ExcelUtil<WarehouseLogs> util = new ExcelUtil<>(WarehouseLogs.class);
        return util.exportExcel(list, "warehouse");
    }

    @PreAuthorize("@ss.hasPermi('recovery:warehouse:export')")
    @GetMapping(value = "/exportGoods")
    public AjaxResult exportGoods(@RequestParam("id") Long id)
    {
        List<TransferGoods> list = warehouseLogsService.queryGoodsById(id);
        ExcelUtil<TransferGoods> util = new ExcelUtil<>(TransferGoods.class);
        return util.exportExcel(list, "warehouse");
    }

    /**
     * 获取出入库日志详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(warehouseLogsService.selectWarehouseLogsById(id));
    }

    /**
     * 新增出入库日志
     */
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseLogs warehouseLogs)
    {
        return toAjax(warehouseLogsService.insertWarehouseLogs(warehouseLogs));
    }

    /**
     * 修改出入库日志
     */
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseLogs warehouseLogs)
    {
        return toAjax(warehouseLogsService.updateWarehouseLogs(warehouseLogs));
    }

    @PutMapping("/confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id) {
        return toAjax(warehouseLogsService.confirm(id));
    }

    @PutMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id) {
        return toAjax(warehouseLogsService.cancel(id));
    }

    @GetMapping("/queryGoodsLogList")
    public AjaxResult queryGoodsLogList(@RequestParam("goodsId") String goodsId) {
        return AjaxResult.success(warehouseLogsService.queryGoodsDetailLogList(goodsId));
    }
}
